 package server.quest;

 import client.MapleCharacter;
 import client.MapleQuestStatus;
 import client.MapleTraitType;
 import client.inventory.Item;
 import client.inventory.MapleInventoryType;
 import client.inventory.MaplePet;
 import client.skills.Skill;
 import client.skills.SkillFactory;
 import constants.ItemConstants;
 import constants.SkillConstants;
 import java.io.Serializable;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Calendar;
 import java.util.LinkedList;
 import java.util.List;
 import tools.Pair;


 public class MapleQuestRequirement
   implements Serializable
 {
   private static final long serialVersionUID = 9179541993413738569L;
   private final MapleQuest quest;
   private final MapleQuestRequirementType type;
   private int intStore;
   private String stringStore;
   private List<Pair<Integer, Integer>> dataStore;

   public MapleQuestRequirement(MapleQuest quest, MapleQuestRequirementType type, ResultSet rse) throws SQLException {
     String[] first, second;
     int i;
/*  35 */     this.type = type;
/*  36 */     this.quest = quest;

/*  38 */     switch (type) {
       case pet:
       case mbcard:
       case mob:
       case item:
       case quest:
       case skill:
       case job:
/*  46 */         this.dataStore = new LinkedList<>();
/*  47 */         first = rse.getString("intStoresFirst").split(", ");
/*  48 */         second = rse.getString("intStoresSecond").split(", ");
/*  49 */         if (first.length <= 0 && rse.getString("intStoresFirst").length() > 0) {
/*  50 */           this.dataStore.add(new Pair(Integer.valueOf(Integer.parseInt(rse.getString("intStoresFirst"))), Integer.valueOf(Integer.parseInt(rse.getString("intStoresSecond")))));
         }
/*  52 */         for (i = 0; i < first.length; i++) {
/*  53 */           if (first[i].length() > 0 && second[i].length() > 0) {
/*  54 */             this.dataStore.add(new Pair(Integer.valueOf(Integer.parseInt(first[i])), Integer.valueOf(Integer.parseInt(second[i]))));
           }
         }
         break;

       case partyQuest_S:
       case dayByDay:
       case normalAutoStart:
       case subJobFlags:
       case fieldEnter:
       case pettamenessmin:
       case npc:
       case questComplete:
       case pop:
       case interval:
       case mbmin:
       case lvmax:
       case lvmin:
/*  72 */         this.intStore = Integer.parseInt(rse.getString("stringStore"));
         break;

       case end:
/*  76 */         this.stringStore = rse.getString("stringStore"); break;
     }  } public boolean check(MapleCharacter chr, Integer npcid) { String timeStr;
     Calendar cal;
     MaplePet[] pet;
     int i;
     int[] partyQuests;
     int sRankings;
/*  83 */     switch (this.type) {
       case job:
/*  85 */         for (Pair<Integer, Integer> a : this.dataStore) {
/*  86 */           if (((Integer)a.getRight()).intValue() == chr.getJob() || chr.isGM()) {
/*  87 */             return true;
           }
         }
/*  90 */         return false;
       case skill:
/*  92 */         for (Pair<Integer, Integer> a : this.dataStore) {
/*  93 */           boolean acquire = (((Integer)a.getRight()).intValue() > 0);
/*  94 */           int skill = ((Integer)a.getLeft()).intValue();
/*  95 */           Skill skil = SkillFactory.getSkill(skill);
/*  96 */           if (acquire) {
/*  97 */             if (SkillConstants.isFourthJob(skill)) {
/*  98 */               if (chr.getMasterLevel(skil) == 0)
/*  99 */                 return false;  continue;
             }
/* 101 */             if (skil.isGuildSkill()) {
/* 102 */               return (chr.getGuild() != null && chr.getGuild().getLevel() >= 1 && chr.getGuild().hasSkill(skill));
             }
/* 104 */             if (chr.getSkillLevel(skil) == 0) {
/* 105 */               return false;
             }
             continue;
           }
/* 109 */           if (chr.getSkillLevel(skil) > 0 || chr.getMasterLevel(skil) > 0) {
/* 110 */             return false;
           }
         }

/* 114 */         return true;

       case quest:
/* 117 */         for (Pair<Integer, Integer> a : this.dataStore) {
/* 118 */           MapleQuestStatus q = chr.getQuest(MapleQuest.getInstance(((Integer)a.getLeft()).intValue()));
/* 119 */           int state = ((Integer)a.getRight()).intValue();
/* 120 */           if (state == 0 || (
/* 121 */             q == null && state == 0)) {
             continue;
           }
/* 124 */           if (q == null || q.getStatus() != state) {
/* 125 */             return false;
           }
         }

/* 129 */         return true;




       case item:
/* 135 */         for (Pair<Integer, Integer> a : this.dataStore) {
/* 136 */           int itemId = ((Integer)a.getLeft()).intValue();
/* 137 */           short quantity = 0;
/* 138 */           MapleInventoryType iType = ItemConstants.getInventoryType(itemId);
/* 139 */           for (Item item : chr.getInventory(iType).listById(itemId)) {
/* 140 */             quantity = (short)(quantity + item.getQuantity());
           }
/* 142 */           int count = ((Integer)a.getRight()).intValue();
/* 143 */           if (quantity < count || (count <= 0 && quantity > 0)) {
/* 144 */             return false;
           }
         }
/* 147 */         return true;
       case lvmin:
/* 149 */         return (chr.getLevel() >= this.intStore);
       case lvmax:
/* 151 */         return (chr.getLevel() <= this.intStore);
       case end:
/* 153 */         timeStr = this.stringStore;
/* 154 */         if (timeStr == null || timeStr.length() <= 0) {
/* 155 */           return true;
         }
/* 157 */         cal = Calendar.getInstance();
/* 158 */         cal.set(Integer.parseInt(timeStr.substring(0, 4)), Integer.parseInt(timeStr.substring(4, 6)), Integer.parseInt(timeStr.substring(6, 8)), Integer.parseInt(timeStr.substring(8, 10)), 0);
/* 159 */         return (cal.getTimeInMillis() >= System.currentTimeMillis());
       case mob:
/* 161 */         for (Pair<Integer, Integer> a : this.dataStore) {
/* 162 */           int mobId = ((Integer)a.getLeft()).intValue();
/* 163 */           int killReq = ((Integer)a.getRight()).intValue();
/* 164 */           if (chr.getQuest(this.quest).getMobKills(mobId) < killReq) {
/* 165 */             return false;
           }
         }
/* 168 */         return true;
       case npc:
/* 170 */         return (npcid == null || npcid.intValue() == this.intStore);
       case fieldEnter:
/* 172 */         return (this.intStore <= 0 || this.intStore == chr.getMapId());
       case mbmin:
/* 174 */         return (chr.getMonsterBook().getSeen() >= this.intStore);
       case mbcard:
/* 176 */         for (Pair<Integer, Integer> a : this.dataStore) {
/* 177 */           int cardId = ((Integer)a.getLeft()).intValue();
/* 178 */           int killReq = ((Integer)a.getRight()).intValue();
/* 179 */           if (chr.getMonsterBook().getLevelByCard(cardId) < killReq) {
/* 180 */             return false;
           }
         }
/* 183 */         return true;
       case pop:
/* 185 */         return (chr.getFame() >= this.intStore);
       case questComplete:
/* 187 */         return (chr.getNumQuest() >= this.intStore);
       case interval:
/* 189 */         return (chr.getQuest(this.quest).getStatus() != 2 || chr.getQuest(this.quest).getCompletionTime() <= System.currentTimeMillis() - (this.intStore * 60) * 1000L);
       case pet:
/* 191 */         for (Pair<Integer, Integer> a : this.dataStore) {
/* 192 */           if (chr.getPetByItemId(((Integer)a.getRight()).intValue()) != -1) {
/* 193 */             return true;
           }
         }
/* 196 */         return false;
       case pettamenessmin:
/* 198 */         pet = chr.getSpawnPets();
/* 199 */         for (i = 0; i < 3; i++) {
/* 200 */           if (pet[i] != null && pet[i].getSummoned() && pet[i].getCloseness() >= this.intStore) {
/* 201 */             return true;
           }
         }
/* 204 */         return false;
       case partyQuest_S:
/* 206 */         partyQuests = new int[] { 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1300, 1301, 1302 };
/* 207 */         sRankings = 0;
/* 208 */         for (int j : partyQuests) {
/* 209 */           String rank = chr.getOneInfo(j, "rank");
/* 210 */           if (rank != null && rank.equals("S")) {
/* 211 */             sRankings++;
           }
         }
/* 214 */         return (sRankings >= 5);
       case subJobFlags:
/* 216 */         return (chr.getSubcategory() == this.intStore / 2);
       case craftMin:
       case willMin:
       case charismaMin:
       case insightMin:
       case charmMin:
       case senseMin:
/* 223 */         return (chr.getTrait(MapleTraitType.getByQuestName(this.type.name())).getLevel() >= this.intStore);
     }
/* 225 */     return true; }



   public MapleQuestRequirementType getType() {
/* 230 */     return this.type;
   }


   public String toString() {
/* 235 */     return this.type.toString();
   }

   public List<Pair<Integer, Integer>> getDataStore() {
/* 239 */     return this.dataStore;
   }
 }


/* Location:              C:\PGX\Server.jar!\server\quest\MapleQuestRequirement.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */